package com.rs.admin.common;


import com.rs.admin.enums.RespEnum;
import lombok.Data;

import java.io.Serializable;


@Data
public class RespResult<T> implements Serializable {


    private String code;

    private String msg;

    private T data;

    public static RespResult buildResult(String code, String msg, Object data) {
        RespResult response = new RespResult();
        response.setCode(code);
        response.setMsg(msg);
        response.setData(data);
        return response;
    }


    public static RespResult buildSuccess() {
        return buildSuccessResult(RespEnum.SUCCESS.getCode(), RespEnum.SUCCESS.getMsg(),null);
    }

    public static RespResult buildSuccess(Object data) {
        return buildSuccessResult(RespEnum.SUCCESS.getCode(), RespEnum.SUCCESS.getMsg(), data);
    }

    public static RespResult buildSuccessResult(Object data) {
        return buildSuccessResult(RespEnum.SUCCESS.getCode(), RespEnum.SUCCESS.getMsg(), data);
    }

    public static RespResult buildSuccessResult(String code, String msg, Object o) {
        return buildResult(code, msg, o);
    }

    public static RespResult buildFail() {
        return buildResult(RespEnum.FAILURE.getCode(), RespEnum.FAILURE.getMsg(), null);
    }

    public static RespResult buildFail(String msg) {
        return buildResult(RespEnum.FAILURE.getCode(), RespEnum.FAILURE.getMsg(), msg);
    }

}
